<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keyword" content="">

    <title>公司列表</title>

    <!-- Bootstrap core CSS -->
    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="__PUBLIC__/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="__PUBLIC__/css/style.css" rel="stylesheet">
    <link href="__PUBLIC__/css/style-responsive.css" rel="stylesheet" />
    <!-- new styles-->
      <link href="__PUBLIC__/css/xxxstyle.css" rel="stylesheet" />
      <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

  <section id="container" class="">
      <!--main content start-->
      <section id="main-content">
          <section class="wrapper site-min-height">
              <!-- page start-->
              <section class="panel">
                  <header class="panel-heading"><i class="glyphicon glyphicon-home"></i>公司列表
                      <span class="pull-right">
                          <button type="button" id="newFolder-btn" class="btn btn-submit btn-xs" data-toggle="modal" href="#add_company"><i class="icon-plus"></i>添加</button>
                      </span>
                  </header>
                  <div class="box-body">
			        <div class="row">
			            <div class="col-sm-12">
			              <table id="list-table" class="table table-hover p-table">
			                <thead>
			                   	<tr role="row">
				                   <th>公司名</th>
		                           <th class="companyListDuan1">操作</th>
			                	</tr>
			                </thead>
							<tbody class="companyListTbody">
								<foreach name="data" item="vo" key="k" >
							  	<tr role="row" align="center" class="{$vo.level}" id="{$vo.level}_{$vo.cat_id}">
			                    	<td class="sorting_1" align="left"> 
							      		<span>{$vo.cat_name}</span>
							     	</td>			
							        <td class="companyListDuan1">
		                        	  	<span class="btn btn-primary btn-xs" style="cursor:pointer;" onclick="editc('{$vo.cat_name}',{$vo.cat_id})"><i class="icon-edit"></i>编辑</span>
		                              	<span class="btn btn-danger btn-xs" onclick="edit_company({$vo.cat_id})"><i class="icon-trash"></i>删除</span>
		                            </td>		     
			                   	</tr>
			                  	</foreach>
			                </tbody>
			              </table>
			            </div>
			        </div>
	             </div><!-- /.box-body -->
              </section>
              <!-- page end-->
               <div class="row">
              	    <div class="col-xs-12 text-center">{$page}</div>		
              </div>
          </section>
          <!-- modal -->
      </section>
      <!--main content end-->
  </section>
  		<!--新建文公司（Modal） -->
	       <div class="modal fade" id="add_company" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">新建公司</h4>
                                </div>
                                    <div class="modal-body">
                                     <div class="form-group">
                                      <div class="form-group">
                                        <label class="col-sm-3 control-label">公司名称</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" name="cname">
                                        </div>
                                      </div>
                                   </div>
                                <div class="modal-footer">
                                    <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                    <button class="btn btn-submit" type="button" onclick="add_company()">创建</button>
                                </div>
                            </div>
                       </div>
           </div>
           </div>
           <!--编辑公司（Modal） -->
	       <div class="modal fade" id="edit_company" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">新建公司</h4>
                                </div>
                                    <div class="modal-body">
                                     <div class="form-group">
                                      <div class="form-group">
                                        <label class="col-sm-3 control-label">公司名称</label>
                                        <div class="col-sm-9">
                                            <input type="text" class="form-control" name="ename">
                                             <input type="hidden" name="id">
                                        </div>
                                      </div>
                                   </div>
                                <div class="modal-footer">
                                    <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                    <button class="btn btn-submit" type="button" onclick="edit_company()">修改</button>
                                </div>
                            </div>
                       </div>
           </div>
           </div>
    <!-- js placed at the end of the document so the pages load faster -->
    <script src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
    <script src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script class="include" type="text/javascript" src="__PUBLIC__/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="__PUBLIC__/js/jquery.scrollTo.min.js"></script>
    <script src="__PUBLIC__/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script src="__PUBLIC__/js/jquery.customSelect.min.js" ></script>
    <!--common script for all pages-->
    <script src="__PUBLIC__/js/common-scripts.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>
    <script>
    //创建公司
	    function add_company(){
	    	     var cname = $("input[name='cname']").val(); 
		    	 if(cname==''){
		       		  layer.msg('名称不能为空',{icon:2});
		       		  return;
       	 	     } 
		 		 $.ajax({
	       		 		type : 'post',
	       		 		url : '__URL__/add_company',
	       		 		data : {cat_name:cname},
	       		 		dataType : 'json',
	       		 		success : function(res){
	       		 	     	 if(res.status==0){
								layer.alert(res.info, {icon: 2});
								return;
							 }
	       		 			 if(!res.errNo){
	       		 				 layer.msg(res.msg,{icon:1});
	       		 				 setTimeout("location.reload()",2000);
	       			          }else{
	       			        	 layer.msg(res.msg,{icon:2});
	       			          }
	       		 		}
	       		})
	    }
    //编辑公司
    function edit_company(id=0){
    	 var cat_name = $("input[name='ename']").val();
    	 var cat_id = $("input[name='id']").val(); 
    	 if(id==0 && cat_name==''){
      		  layer.msg('名称不能为空',{icon:2});
      		  return;
	     } 
    	 $.ajax({
		 		type : 'post',
		 		url : '__URL__/edit_company',
		 		data : {cat_id:cat_id,cat_name:cat_name,id:id},
		 		dataType : 'json',
		 		success : function(res){
		 	     	 if(res.status==0){
						layer.alert(res.info, {icon: 2});
						return;
					 }
		 			 if(!res.errNo){
		 				 layer.msg(res.msg,{icon:1});
		 				 setTimeout("location.reload()",2000);
			          }else{
			        	 layer.msg(res.msg,{icon:2});
			          }
		 		}
		})
    }
	    
	    function editc(o,id){
	    	$("input[name='ename']").attr('value',o);
	    	$("input[name='id']").attr('value',id);
	    	$('#edit_company').modal('show');
	    }
    </script>
  </body>
</html>
